package com.front.teacher.teacherapp.view.fragment;


import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;

import com.front.teacher.teacherapp.R;
import com.front.teacher.teacherapp.base.BaseFragment;
import com.front.teacher.teacherapp.presenter.EvaluatePresenter;
import com.front.teacher.teacherapp.view.adapter.TabEvaluateAdapter;
import com.front.teacher.teacherapp.view.impl.IEvaluateView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 作评价碎片
 */
public class EvaluateFragment extends BaseFragment<IEvaluateView, EvaluatePresenter> implements IEvaluateView {
    public static EvaluateFragment evaluateFragment;
    private TabEvaluateAdapter tabEvaluateAdapter;
    private List<Fragment> fragments = new ArrayList<>();
    @InjectView(R.id.class_selector_spinner)
    Spinner classSelectorSpinner;
    @InjectView(R.id.project_selector_spinner)
    Spinner projectSelectorSpinner;
    @InjectView(R.id.type_selector_spinner)
    Spinner typeSelectorSpinner;
    @InjectView(R.id.student_selector_spinner)
    Spinner studentSelectorSpinner;
    @InjectView(R.id.tablayout_evaluate)
    TabLayout tablayoutEvaluate;
    @InjectView(R.id.viewpager_evaluate)
    ViewPager viewpagerEvaluate;

    public static EvaluateFragment newInstance() {
        if (evaluateFragment == null) {
            evaluateFragment = new EvaluateFragment();
        }
        return evaluateFragment;
    }

    @Override
    public EvaluatePresenter initPresenter() {
        return new EvaluatePresenter(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_evaluate;
    }

    @Override
    protected void initData() {
        fragments.add(DynamicFragment.newInstance());
        fragments.add(StatisticsFragment.newInstance());
        tabEvaluateAdapter.notifyDataSetChanged();
    }

    @Override
    protected void initView() {
        String[] arrTitle = getResources().getStringArray(R.array.arrTitles);
        tablayoutEvaluate.setTabMode(TabLayout.MODE_FIXED);
        tabEvaluateAdapter = new TabEvaluateAdapter(getFragmentManager(),fragments,arrTitle);
        viewpagerEvaluate.setAdapter(tabEvaluateAdapter);
        tablayoutEvaluate.setupWithViewPager(viewpagerEvaluate);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
